package com.example.auth3.config;
import com.example.util.utils.Md5Util;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.PasswordEncoder;
/**
 * 因spring security自带的密码加解密管理器是接口，所以使用必须要实现
 * @author shangSshang
 * 2018.12.21 12:00:03
 */
@Configuration
public class MyPasswordEncoder   {
    @Bean
    public PasswordEncoder passwordEncoder() {
        return new PasswordEncoder() {

            @Override
            public boolean matches(CharSequence rawPassword, String encodedPassword) {
                // TODO Auto-generated method stub
                return Md5Util.encode((String)rawPassword).equals(encodedPassword);
            }

            @Override
            public String encode(CharSequence rawPassword) {
                // TODO Auto-generated method stub
                return (String)rawPassword;
            }
        };
    }
}
